import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class AppHomeBannerService {

  /**
   * 列表
   */
  public list_URL = "/banner/list";
  /**
    * 新增
  */
  public save_URL = '/banner/save'
  /**
    * 编辑
  */
  public update_URL = '/banner/update'
  /**
   * 删除 status = 2
 */
  public delete_URL = '/banner/update'
  /**
    * 上移、下移
  */
  public move_URL = '/banner/move'
  /**
   * 文件上传地址
   */
  public file_URL = "/common/upload/file";


  constructor(public httpClient: HttpClient) { }

  /**
   * 列表
   * @params json 参数
   */
  public async getList(params: any) {
    return await this.httpClient.post(this.list_URL, params).toPromise();
  }
  /**
   * 新增
   * @params json 
   */
  public async save(params: any) {
    return await this.httpClient.post(this.save_URL, params).toPromise();
  }
  /**
    * 编辑
    * @params json 
  */
  public async update(params: any) {
    return await this.httpClient.post(this.update_URL, params).toPromise();
  }
  /**
    * 删除
    * @params json  status = 2
  */
  public async delete(params: any) {
    return await this.httpClient.post(this.delete_URL, params).toPromise();
  }
  /**
   * 上移、下移
   * @params json
   */
  public async move(params: any) {
    return await this.httpClient.put(this.move_URL, params).toPromise();
  }
  /**
   * 上传文件
   * @param fileToUpload 
   * @returns 
   */
  public async httpPostFile(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "ihapp");
    return await this.httpClient.post(this.file_URL, formData).toPromise();
  }

}



